5.3 Calculating Least Squares Linear Regression

计算最小二乘线性回归 - 练习题

练习题 / Exercises

基础计算题 / Basic Calculation Problems

问题 1 / Question 1

计算以下数据的最小二乘线性回归方程 \(\hat{y} = a + bx\):

Calculate the least squares linear regression equation \(\hat{y} = a + bx\) for the following data:

x y
1 5
2 7
3 9
4 11
5 13
问题 2 / Question 2

给定以下数据,计算 \(S_{xx}\)、\(S_{xy}\)、斜率 \(b\) 和截距 \(a\),并写出回归方程:

Given the following data, calculate \(S_{xx}\), \(S_{xy}\), slope \(b\), and intercept \(a\), and write the regression equation:

x y
3 6
5 8
7 10
9 12

应用题 / Application Problems

问题 3 / Question 3

某商店记录了过去5天的广告支出(百元)和销售额(千元),数据如下:

A store recorded advertising expenditure (in hundred yuan) and sales revenue (in thousand yuan) for the past 5 days as follows:

广告支出 (x) 销售额 (y)
2 5
3 8
4 9
5 12
6 14

(1)计算销售额对广告支出的回归线方程。

(2)如果某天的广告支出为7百元,预测当天的销售额。

(3)解释斜率的实际意义。

(1) Calculate the regression line equation of sales revenue on advertising expenditure.

(2) Predict the sales revenue when the advertising expenditure is 7 hundred yuan.

(3) Explain the practical meaning of the slope.

问题 4 / Question 4

研究某种产品的产量(千件)与生产成本(万元)之间的关系,收集了以下数据:

A study was conducted on the relationship between production volume (in thousand units) and production cost (in ten thousand yuan) for a product, and the following data were collected:

产量 (x) 成本 (y)
1 3
2 5
3 7
4 8
5 10
6 12

(1)计算生产成本对产量的回归线方程。

(2)如果产量为7千件,预测生产成本。

(3)计算当产量为0时的成本,并解释其意义。

(1) Calculate the regression line equation of production cost on production volume.

(2) Predict the production cost when the production volume is 7 thousand units.

(3) Calculate the cost when production volume is 0 and explain its meaning.

挑战题 / Challenge Problems

问题 5 / Question 5

已知某数据集的统计摘要如下:

The statistical summary of a dataset is given as follows:

样本量 \(n = 8\),\(\sum x = 40\),\(\sum y = 80\),\(\sum x^2 = 250\),\(\sum xy = 450\)

Sample size \(n = 8\), \(\sum x = 40\), \(\sum y = 80\), \(\sum x^2 = 250\), \(\sum xy = 450\)

(1)计算回归系数 \(a\) 和 \(b\)。

(2)写出回归方程。

(3)验证回归直线是否通过点 \((ar{x}, ar{y})\)。

(1) Calculate regression coefficients \(a\) and \(b\).

(2) Write the regression equation.

(3) Verify whether the regression line passes through the point \((ar{x}, ar{y})\).

问题 6 / Question 6

以下是某公司员工工作年限(年)与月薪(千元)的数据:

The following data show the working years and monthly salary (in thousand yuan) of employees in a company:

工作年限 (x) 月薪 (y)
1 5
2 6
3 7
4 9
5 11
6 12
7 14

(1)计算月薪对工作年限的回归线方程。

(2)预测工作年限为8年的员工月薪。

(3)根据回归方程,工作年限每增加1年,月薪平均增加多少?

(1) Calculate the regression line equation of monthly salary on working years.

(2) Predict the monthly salary for an employee with 8 years of working experience.

(3) According to the regression equation, how much does the monthly salary increase on average for each additional year of working experience?

答案与解析 / Answers and Solutions

问题 1 答案 / Answer to Question 1

步骤 1:计算必要的总和:

Step 1: Calculate necessary sums:

x y xy
1 5 1 5
2 7 4 14
3 9 9 27
4 11 16 44
5 13 25 65
∑x=15 ∑y=45 ∑x²=55 ∑xy=155

步骤 2:计算平均值:

Step 2: Calculate means:

\(\bar{x} = \frac{15}{5} = 3\)

\(\bar{y} = \frac{45}{5} = 9\)

步骤 3:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 3: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 55 - \frac{15^2}{5} = 55 - 45 = 10\)

\(S_{xy} = 155 - \frac{15 \times 45}{5} = 155 - 135 = 20\)

步骤 4:计算斜率 \(b\) 和截距 \(a\):

Step 4: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{20}{10} = 2\)

\(a = 9 - 2 \times 3 = 9 - 6 = 3\)

因此,回归方程为:

Therefore, the regression equation is:

\[\hat{y} = 3 + 2x\]

问题 2 答案 / Answer to Question 2

步骤 1:计算必要的总和:

Step 1: Calculate necessary sums:

x y xy
3 6 9 18
5 8 25 40
7 10 49 70
9 12 81 108
∑x=24 ∑y=36 ∑x²=164 ∑xy=236

步骤 2:计算平均值:

Step 2: Calculate means:

\(\bar{x} = \frac{24}{4} = 6\)

\(\bar{y} = \frac{36}{4} = 9\)

步骤 3:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 3: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 164 - \frac{24^2}{4} = 164 - 144 = 20\)

\(S_{xy} = 236 - \frac{24 \times 36}{4} = 236 - 216 = 20\)

步骤 4:计算斜率 \(b\) 和截距 \(a\):

Step 4: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{20}{20} = 1\)

\(a = 9 - 1 \times 6 = 9 - 6 = 3\)

因此,回归方程为:

Therefore, the regression equation is:

\[\hat{y} = 3 + x\]

问题 3 答案 / Answer to Question 3

(1)计算销售额对广告支出的回归线方程:

(1) Calculate the regression line equation of sales revenue on advertising expenditure:

步骤 1:计算必要的总和:

Step 1: Calculate necessary sums:

x y xy
2 5 4 10
3 8 9 24
4 9 16 36
5 12 25 60
6 14 36 84
∑x=20 ∑y=48 ∑x²=90 ∑xy=214

步骤 2:计算平均值:

Step 2: Calculate means:

\(\bar{x} = \frac{20}{5} = 4\)

\(\bar{y} = \frac{48}{5} = 9.6\)

步骤 3:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 3: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 90 - \frac{20^2}{5} = 90 - 80 = 10\)

\(S_{xy} = 214 - \frac{20 \times 48}{5} = 214 - 192 = 22\)

步骤 4:计算斜率 \(b\) 和截距 \(a\):

Step 4: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{22}{10} = 2.2\)

\(a = 9.6 - 2.2 \times 4 = 9.6 - 8.8 = 0.8\)

因此,回归方程为:

Therefore, the regression equation is:

\[\hat{y} = 0.8 + 2.2x\]

(2)预测广告支出为7百元时的销售额:

(2) Predict the sales revenue when advertising expenditure is 7 hundred yuan:

\(\hat{y} = 0.8 + 2.2 \times 7 = 0.8 + 15.4 = 16.2\)

预测销售额为16.2千元。

The predicted sales revenue is 16.2 thousand yuan.

(3)斜率的实际意义:

(3) Practical meaning of the slope:

斜率 \(b = 2.2\) 表示广告支出每增加1百元,销售额平均增加2.2千元。

The slope \(b = 2.2\) indicates that for each increase of 1 hundred yuan in advertising expenditure, sales revenue increases by an average of 2.2 thousand yuan.

问题 4 答案 / Answer to Question 4

(1)计算生产成本对产量的回归线方程:

(1) Calculate the regression line equation of production cost on production volume:

步骤 1:计算必要的总和:

Step 1: Calculate necessary sums:

x y xy
1 3 1 3
2 5 4 10
3 7 9 21
4 8 16 32
5 10 25 50
6 12 36 72
∑x=21 ∑y=45 ∑x²=91 ∑xy=188

步骤 2:计算平均值:

Step 2: Calculate means:

\(\bar{x} = \frac{21}{6} = 3.5\)

\(\bar{y} = \frac{45}{6} = 7.5\)

步骤 3:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 3: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 91 - \frac{21^2}{6} = 91 - 73.5 = 17.5\)

\(S_{xy} = 188 - \frac{21 \times 45}{6} = 188 - 157.5 = 30.5\)

步骤 4:计算斜率 \(b\) 和截距 \(a\):

Step 4: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{30.5}{17.5} \approx 1.7429\)

\(a = 7.5 - 1.7429 \times 3.5 \approx 7.5 - 6.1002 = 1.3998\)

因此,回归方程为:

Therefore, the regression equation is:

\[\hat{y} \approx 1.40 + 1.74x\]

(2)预测产量为7千件时的生产成本:

(2) Predict the production cost when production volume is 7 thousand units:

\(\hat{y} = 1.40 + 1.74 \times 7 = 1.40 + 12.18 = 13.58\)

预测生产成本为13.58万元。

The predicted production cost is 13.58 ten thousand yuan.

(3)当产量为0时的成本:

(3) Cost when production volume is 0:

\(\hat{y} = 1.40 + 1.74 \times 0 = 1.40\)

意义:当产量为0时,成本为1.40万元,这代表固定成本,即即使不生产任何产品也需要支付的成本。

Meaning: When production volume is 0, the cost is 1.40 ten thousand yuan, which represents the fixed cost, i.e., the cost that needs to be paid even if no products are produced.

问题 5 答案 / Answer to Question 5

已知:样本量 \(n = 8\),\(\sum x = 40\),\(\sum y = 80\),\(\sum x^2 = 250\),\(\sum xy = 450\)

Given: Sample size \(n = 8\), \(\sum x = 40\), \(\sum y = 80\), \(\sum x^2 = 250\), \(\sum xy = 450\)

(1)计算回归系数 \(a\) 和 \(b\):

(1) Calculate regression coefficients \(a\) and \(b\):

步骤 1:计算平均值:

Step 1: Calculate means:

\(\bar{x} = \frac{40}{8} = 5\)

\(\bar{y} = \frac{80}{8} = 10\)

步骤 2:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 2: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 250 - \frac{40^2}{8} = 250 - 200 = 50\)

\(S_{xy} = 450 - \frac{40 \times 80}{8} = 450 - 400 = 50\)

步骤 3:计算斜率 \(b\) 和截距 \(a\):

Step 3: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{50}{50} = 1\)

\(a = 10 - 1 \times 5 = 10 - 5 = 5\)

(2)回归方程:

(2) Regression equation:

\[\hat{y} = 5 + x\]

(3)验证回归直线是否通过点 \((\bar{x}, \bar{y})\):

(3) Verify whether the regression line passes through the point \((\bar{x}, \bar{y})\):

将 \(\bar{x} = 5\) 代入回归方程:

Substitute \(\bar{x} = 5\) into the regression equation:

\(\hat{y} = 5 + 1 \times 5 = 10\)

因为 \(\hat{y} = 10 = \bar{y}\),所以回归直线确实通过点 \((\bar{x}, \bar{y})\)。

Since \(\hat{y} = 10 = \bar{y}\), the regression line does pass through the point \((\bar{x}, \bar{y})\).

问题 6 答案 / Answer to Question 6

(1)计算月薪对工作年限的回归线方程:

(1) Calculate the regression line equation of monthly salary on working years:

步骤 1:计算必要的总和:

Step 1: Calculate necessary sums:

x y xy
1 5 1 5
2 6 4 12
3 7 9 21
4 9 16 36
5 11 25 55
6 12 36 72
7 14 49 98
∑x=28 ∑y=64 ∑x²=140 ∑xy=299

步骤 2:计算平均值:

Step 2: Calculate means:

\(\bar{x} = \frac{28}{7} = 4\)

\(\bar{y} = \frac{64}{7} \approx 9.1429\)

步骤 3:计算 \(S_{xx}\) 和 \(S_{xy}\):

Step 3: Calculate \(S_{xx}\) and \(S_{xy}\):

\(S_{xx} = 140 - \frac{28^2}{7} = 140 - 112 = 28\)

\(S_{xy} = 299 - \frac{28 \times 64}{7} = 299 - 256 = 43\)

步骤 4:计算斜率 \(b\) 和截距 \(a\):

Step 4: Calculate slope \(b\) and intercept \(a\):

\(b = \frac{43}{28} \approx 1.5357\)

\(a = 9.1429 - 1.5357 \times 4 \approx 9.1429 - 6.1428 = 3.0001\)

因此,回归方程为:

Therefore, the regression equation is:

\[\hat{y} \approx 3.00 + 1.54x\]

(2)预测工作年限为8年的员工月薪:

(2) Predict the monthly salary for an employee with 8 years of working experience:

\(\hat{y} = 3.00 + 1.54 \times 8 = 3.00 + 12.32 = 15.32\)

预测月薪为15.32千元。

The predicted monthly salary is 15.32 thousand yuan.

(3)工作年限每增加1年,月薪平均增加量:

(3) Average increase in monthly salary for each additional year of working experience:

根据回归方程,斜率 \(b \approx 1.54\) 表示工作年限每增加1年,月薪平均增加约1.54千元。

According to the regression equation, the slope \(b \approx 1.54\) indicates that for each additional year of working experience, the monthly salary increases by an average of approximately 1.54 thousand yuan.